<div class="row">
<div class="col-xs-12">
	<div class="box">
		<div class="box-header">
			<form id="auto-query-form" class="form-inline" method="post" role="form">
				<div class="form-group">
					<label class="control-label" for="query.keyword">关键字</label>
					<input id="query.keyword" name="query.keyword" placeholder="请输入关键字" class="form-control"/>
				</div>
				<div class="form-group">
					<label class="control-label" for="query.type">任务组</label>
					<input id="query.type" name="query.type" placeholder="请输入任务组" class="form-control"/>
				</div>				
				<div class="form-group">
					#@query_btn()
				</div>
			</form>
		</div>

		<div class="box-body">
			<table id="auto_data_table" class="table table-striped table-hover table-bordered dataTable no-footer" width="100%">
			</table>
		</div>

		<div class="box-footer text-center">
			#@add_btn("schedule/index",true)
			#@edit_btn("schedule/index",true)
			#@auth_btn("pause","暂停","schedule/index",true,"btn-info","fa fa-pause")
			#@auth_btn("resume","恢复","schedule/index",true,"btn-primary","fa fa-eject")
			#@auth_btn("run","立即执行","schedule/index",true,"btn-success","fa fa-play")
			#@auth_btn("start","启用","schedule/index",true,"btn-primary","fa fa-square-o")
			#@auth_btn("disable","禁用","schedule/index",true,"btn-warning","fa fa-square")
			#@del_btn("schedule/index",true)
		</div>
	</div>
</div>
</div>
<script type="text/javascript">
	$(document).ready(function() {
		var dtSelf = $('#auto_data_table').autoDataTable({
			controller : "schedule",
			title : "系统定时任务",
			columns : [
			   { "data" : "code", "name" : "code", "title" : "任务代码" },
			   { "data" : "name", "name" : "name", "title" : "任务名称" },
			   { "data" : "type", "name" : "type", "title" : "任务组" },
			   { "data" : "prev_time", "name" : "prev_time", "title" : "最近运行时间",orderable: false },
			   { "data" : "next_time", "name" : "next_time", "title" : "下次运行时间",orderable: false },
			   { "data" : "server_ip", "name" : "server_ip", "title" : "服务器" },
			   { "data" : "state", "name" : "state", "title" : "任务状态" , render : function(data, type, row) {
	                return dict_name("SCHEDULER_STATE",data);
	            } }
			]
		});

		$("#pause_btn,#resume_btn,#run_btn,#start_btn,#disable_btn").click(function(){
			var $this = $(this);
			var action = $this.attr("id").replaceAll("_btn","");
			var msg = $this.text();
			var ids = new Array();
			$("#auto_data_table tr.selected").each(function() {
				row=dtSelf.fnGetData(this);
				if(row.state=="DISABLE"){//禁用状态只能启用
					if(action=="start"){
						ids.push(row.id);
					}
				}else{
					ids.push(row.id);
				}
			});
			if(ids.length<1){
				showMsg("请选择有效的定时任务(禁用状态的任务先启用才能正常运行,运行服务器设置不对也会被禁用)","error");
				return;
			}
			confirmDialog("<strong class='text-danger'>确定要"+msg+"    选中定时任务吗？</strong>", function() {

				var datas = {action : action,ids:ids};
				postData("schedule/control", datas, null, function(data) {
					if(data.success)dtSelf.fnDraw();
				});
			});
		});
	});
</script>